import request from '@/utils/request'

// 获取新的商品信息
export const getNewCartGoods = (skuId) => {
  return request(`/goods/stock/${skuId}`, 'get')
}

/**
 * 合并本地购物车
 * @param {Array<object>} cartList - 本地购物车数组
 * @param {String} item.skuId - 商品SKUID
 * @param {Boolean} item.selected - 是否选中
 * @param {Integer} item.count - 数量
 */
export const mergeCart = (cartList) => {
  return request('/member/cart/merge', 'post', cartList)
}

// 获取登录后购物车列表
export const getCartList = () => {
  return request('/member/cart', 'get')
}

// 加入购物车
export const insertCart = ({ skuId, count }) => {
  return request('/member/cart', 'post', { skuId, count })
}

// 删除购物车商品
export const deleteCart = (ids) => {
  return request('/member/cart', 'delete', { ids })
}

// 修改商品数量和状态
export const updateCart = (goods) => {
  return request(`/member/cart/${goods.skuId}`, 'put', goods)
}

// 全选反选
export const checkAllCart = ({ selected, ids }) => {
  return request('/member/cart/selected', 'put', { selected, ids })
}
